#include "../math/MathLib.h"
#include "Camera.h"

namespace cy_univerX
{
namespace render
{

CRenderCamera::CRenderCamera():
	m_Forward(0,0,1),
	m_Up(0,1,0),
	m_CamPos(0,0,0),
	m_ViewMatrix(1)
{
}

void CRenderCamera::SetOrthoInfo(float width, float aspect, float near, float far)
{
	m_PerspOrtho = false;
	m_Width = width;
	m_Aspect = aspect;
	m_NearPlane = near;
	m_FarPlane = far;
	math::GetOrthoProjMatrix(m_ProjMatrix, m_Width, m_Width*m_Aspect, m_NearPlane, m_FarPlane);
}
void CRenderCamera::SetPerspInfo(float fov, float aspect, float near, float far)
{
	m_PerspOrtho = true;
	m_Fov = fov;
	m_Aspect = aspect;
	m_NearPlane = near;
	m_FarPlane = far;
	math::GetPerspProjMatrix(m_ProjMatrix, m_Fov, m_Aspect, m_NearPlane, m_FarPlane);
}
void CRenderCamera::SetFov(float fov)
{
	m_PerspOrtho = true;
	m_Fov = fov;
	math::GetPerspProjMatrix(m_ProjMatrix, m_Fov, m_Aspect, m_NearPlane, m_FarPlane);
}
void CRenderCamera::SetWidth(float width)
{
	m_PerspOrtho = false;
	m_Width = width;
	math::GetOrthoProjMatrix(m_ProjMatrix, m_Width, m_Width*m_Aspect, m_NearPlane, m_FarPlane);
}
void CRenderCamera::SetNearFarPlane(float near, float far)
{
	m_NearPlane = near;
	m_FarPlane = far;
	if (m_PerspOrtho)
		math::GetPerspProjMatrix(m_ProjMatrix, m_Fov, m_Aspect, m_NearPlane, m_FarPlane);
	else
		math::GetOrthoProjMatrix(m_ProjMatrix, m_Width, m_Width*m_Aspect, m_NearPlane, m_FarPlane);
}
void CRenderCamera::SetAspect(float aspect)
{
	m_Aspect = aspect;
	if (m_PerspOrtho)
		math::GetPerspProjMatrix(m_ProjMatrix, m_Fov, m_Aspect, m_NearPlane, m_FarPlane);
	else
		math::GetOrthoProjMatrix(m_ProjMatrix, m_Width, m_Width*m_Aspect, m_NearPlane, m_FarPlane);
}

void CRenderCamera::SetViewInfo(const math::CVector3f& forward, const math::CVector3f& up, const math::CVector3f& pos)
{
	m_Forward = forward;
	m_Up = up;
	m_CamPos = pos;
	math::GetViewMatrix(m_ViewMatrix, m_CamPos, m_Forward, m_Up);
}
void CRenderCamera::SetCamPos(const math::CVector3f& pos)
{
	m_CamPos = pos;
	math::GetViewMatrix(m_ViewMatrix, m_CamPos, m_Forward, m_Up);
}
void CRenderCamera::SetCamDir(const math::CVector3f& forward, const math::CVector3f& up)
{
	m_Forward = forward;
	m_Up = up;
	math::GetViewMatrix(m_ViewMatrix, m_CamPos, m_Forward, m_Up);
}

}
}